package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Slf4j
@RestController
@Api(tags = "套餐controller层")
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;
    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> SetmealPage(SetmealPageQueryDTO setmealPageQueryDTO){
            PageResult pageResult = setmealService.PageQuery(setmealPageQueryDTO );
        return Result.success(pageResult);
    }

    @ApiOperation("新增套餐")
    @PostMapping()
    public Result AddSetmeal(@RequestBody SetmealDTO setmealDTO){


        setmealService.AddSetmeal(setmealDTO);

        return Result.success();
    }

    @ApiOperation("根据id查询菜单")
    @GetMapping("/{id}")
    public Result<SetmealDTO> FindSetmealById(@PathVariable Integer id){
        SetmealDTO setmealDTO = setmealService.FindSetmealById(id);
        return Result.success(setmealDTO);
    }

    /**
     * 启用和禁用套餐
     * @return
     */
    @PostMapping("status/{status}")
    @ApiOperation("启用和禁用套餐")
    public Result UpdateStutas(@PathVariable Integer status,Long id){

        setmealService.UpdateStutas(status,id);

        return Result.success();
    }
    @PutMapping()
    public Result UpDateSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.UpDateSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 批量删除套餐
     * @return
     */
    @DeleteMapping()
    public Result DeleteSetmealList(@RequestParam List<Long> ids) {
        for (Long id : ids) {
            setmealService.DeleteSetmealList(id);
        }
        return Result.success();
    }

}
